import Vue from 'vue'
import Router from 'vue-router'
import Main from '@/views/Main'
import Empty from '@/views/Empty'
import Login from '@/views/Login'
import Gallery from '@/views/Gallery'


import User from '@/views/merchant/User'
import Shop from '@/views/merchant/Shop'
import ShopDetail from '@/views/merchant/ShopDetail'
import MerchantInfo from '@/views/merchant/MerchantInfo'
import Album from '@/views/merchant/Album'
import CustomerDetail from '@/views/merchant/CustomerDetail'
import CustomerPage from '@/views/merchant/Customer'
import ReservePage from '@/views/merchant/Reserve'


import DpShop from '@/views/dp/DpShop'
import DpShopDetail from '@/views/dp/DpShopDetail'
import DpShopHistory from '@/views/dp/DpShopHistory'
import DpRank from '@/views/dp/DpRank'
import DpRankDetail from '@/views/dp/DpRankDetail'
import DpRankShop from '@/views/dp/DpRankShop'
import DpCpcPlanDetail from '@/views/dp/DpCpcPlanDetail'
import DpShopAnalysis from '@/views/dp/DpShopAnalysis'
import DpShopSummary from '@/views/dp/DpShopSummary'
import DpCompareByShop from '@/views/dp/DpCompareByShop'
import DpCompareByDate from '@/views/dp/DpCompareByDate'


import OfficialAccount from '@/views/mp/officialaccount/OfficalAccount'
import OfficialAccountDetail from '@/views/mp/officialaccount/OfficialAccountDetail'
import MpQrcode from '@/views/mp/officialaccount/MpQrcode'
import MpMaterial from '@/views/mp/officialaccount/MpMaterial'


import MiniProgram from '@/views/mp/miniprogram/MiniProgram'
import MiniProgramDetail from '@/views/mp/miniprogram/MiniProgramDetail'
import MnpConfig from '@/views/mp/miniprogram/MnpConfig'
import MnpQrcode from '@/views/mp/miniprogram/MnpQrcode'
import MnpLink from '@/views/mp/miniprogram/MnpLink'


import OpenAccount from '@/views/mp/OpenAccount'
import WxPay from '@/views/mp/WxPay'


import Permission from '@/views/admin/Permission'
import MerchantAdmin from '@/views/admin/MerchantAdmin'
import WorkAppConfig from '@/views/admin/WorkAppConfig'
import OpenThirdConfig from "@/views/admin/OpenThirdConfig";
import OpenThirdDetail from "@/views/admin/OpenThirdDetail";
import SystemConfig from '@/views/admin/SystemConfig'
import BacklogPage from '@/views/admin/BacklogPage'


import MemberCard from '@/views/member/MemberCard'
import MemberCardDetail from '@/views/member/MemberCardDetail'
import MemberDetail from '@/views/member/MemberDetail'
import Coupon from '@/views/member/Coupon'
import CouponDetail from '@/views/member/CouponDetail'
import CouponMarketing from '@/views/member/CouponMarketing'
import CouponMarketingDetail from '@/views/member/CouponMarketingDetail'
import SmsMarketing from '@/views/member/SmsMarketing'
import SmsMarketingDetail from '@/views/member/SmsMarketingDetail'


import WorkCorp from '@/views/workwx/WorkCorp'
import WorkCorpDetail from '@/views/workwx/WorkCorpDetail'
import WorkGroupChatDetail from '@/views/workwx/WorkGroupChatDetail'
import WorkQrcodeGroup from '@/views/workwx/WorkQrcodeGroup'
import WorkQrcodeGroupDetail from '@/views/workwx/WorkQrcodeGroupDetail'


import DpKol from '@/views/k/kol/DpKol'
import DyKol from '@/views/k/kol/DyKol'
import XhsKol from '@/views/k/kol/XhsKol'
import KolDetail from '@/views/k/kol/detail/KolDetail'
import Task from '@/views/k/Task'
import TaskDetail from '@/views/k/TaskDetail'
import TaskMerchant from '@/views/k/TaskMerchant'


import db from '@/utils/localstorage'
import NProgress from "nprogress"

Vue.use(Router);

let router = new Router({
    routes: [
        {
            path: '/login',
            component: Login,
            name: '登录',
            hidden: true
        },
        {
            path: '/gallery',
            component: Gallery,
            name: '美食相册',
            hidden: true
        },
        {
            path: '/dp/shop/analysis',
            name: '门店分析',
            component: DpShopAnalysis,
        },
        {
            path: '/dp/shop/summary',
            name: '门店数据汇总',
            component: DpShopSummary,
        },
        {
            path: '/dp/shop/compareByShop',
            name: '门店数据对比',
            component: DpCompareByShop,
        },
        {
            path: '/dp/shop/compareByDate',
            name: '日期数据对比',
            component: DpCompareByDate,
        },
        {
            path: '/k/task/merchant',
            name: '商家选号',
            component: TaskMerchant,
        },
        {
            path: '/',
            name: 'Main',
            component: Main,
            children: [
                {
                    path: 'admin',
                    name: 'ADMIN',
                    component: Empty,
                    children: [
                        {
                            path: 'permission',
                            name: '权限管理',
                            component: Permission,
                        },
                        {
                            path: 'merchant',
                            name: '商户管理',
                            component: MerchantAdmin,
                        },
                        {
                            path: 'wx/work/config',
                            name: '企微应用配置',
                            component: WorkAppConfig,
                        },
                        {
                            path: 'wx/open/config',
                            name: '开放平台配置',
                            component: OpenThirdConfig,
                        },
                        {
                            path: 'wx/open/config/detail',
                            name: '开放平台详情',
                            component: OpenThirdDetail,
                        },
                        {
                            path: 'systemConfig',
                            name: '系统配置',
                            component: SystemConfig,
                        },
                        {
                            path: 'backlog',
                            name: '代办事项',
                            component: BacklogPage,
                        },
                    ]
                },
                {
                    path: 'merchant',
                    name: 'MERCHANT',
                    component: Empty,
                    children: [
                        {
                            path: 'user',
                            name: '用户管理',
                            component: User,
                        },
                        {
                            path: 'shop',
                            name: '门店管理',
                            component: Shop,
                        },
                        {
                            path: 'shop/detail',
                            name: '门店详情',
                            component: ShopDetail,
                        },
                        {
                            path: 'info',
                            name: '商户信息',
                            component: MerchantInfo,
                        },
                        {
                            path: 'album',
                            name: '相册管理',
                            component: Album,
                        },
                        {
                            path: 'shop/customer/detail',
                            name: '顾客详情',
                            component: CustomerDetail,
                        },
                        {
                            path: 'customer',
                            name: '顾客管理',
                            component: CustomerPage,
                        },
                        {
                            path: 'reserve',
                            name: '预定管理',
                            component: ReservePage,
                        },
                    ]
                },
                {
                    path: 'mp',
                    name: 'MP',
                    component: Empty,
                    children: [
                        {
                            path: 'official-account',
                            name: '公众号',
                            component: OfficialAccount,
                        },
                        {
                            path: 'official-account/detail',
                            name: '公众号详情',
                            component: OfficialAccountDetail,
                        },
                        {
                            path: 'official-account/qrcode',
                            name: '公众号二维码',
                            component: MpQrcode,
                        },
                        {
                            path: 'official-account/material',
                            name: '公众号素材管理',
                            component: MpMaterial,
                        },
                        {
                            path: 'mini-program',
                            name: '小程序',
                            component: MiniProgram,
                        },
                        {
                            path: 'mini-program/detail',
                            name: '小程序详情',
                            component: MiniProgramDetail,
                        },
                        {
                            path: 'mini-program/config',
                            name: '广告配置',
                            component: MnpConfig,
                        },
                        {
                            path: 'mini-program/qrcode',
                            name: '二维码配置',
                            component: MnpQrcode,
                        },
                        {
                            path: 'mini-program/link',
                            name: '链接配置',
                            component: MnpLink,
                        },
                        {
                            path: 'open/account',
                            name: '开放平台',
                            component: OpenAccount,
                        },
                        {
                            path: 'wx/pay',
                            name: '微信支付',
                            component: WxPay,
                        }
                    ]
                },
                {
                    path: 'member',
                    name: 'MEMBER',
                    component: Empty,
                    children: [
                        {
                            path: 'card',
                            name: '会员卡管理',
                            component: MemberCard,
                        },
                        {
                            path: 'card/detail',
                            name: '会员卡详情',
                            component: MemberCardDetail,
                        },
                        {
                            path: 'member/detail',
                            name: '会员详情',
                            component: MemberDetail,
                        },
                        {
                            path: 'coupon',
                            name: '优惠券管理',
                            component: Coupon,
                        },
                        {
                            path: 'coupon/detail',
                            name: '优惠券详情',
                            component: CouponDetail,
                        },
                        {
                            path: 'coupon/marketing',
                            name: '智能发券',
                            component: CouponMarketing,
                        },
                        {
                            path: 'coupon/marketing/detail',
                            name: '智能发券详情',
                            component: CouponMarketingDetail,
                        },
                        {
                            path: 'sms/marketing',
                            name: '短信营销',
                            component: SmsMarketing,
                        },
                        {
                            path: 'sms/marketing/detail',
                            name: '短信营销详情',
                            component: SmsMarketingDetail,
                        },
                    ]
                },
                {
                    path: 'dp',
                    name: 'DP',
                    component: Empty,
                    children: [
                        {
                            path: 'shop',
                            name: '门店数据',
                            component: DpShop,
                        },
                        {
                            path: 'shop/detail',
                            name: '门店数据详情',
                            component: DpShopDetail,
                        },
                        {
                            path: 'shop/history',
                            name: '门店数据历史',
                            component: DpShopHistory,
                        },
                        {
                            path: 'rank',
                            name: '点评榜单',
                            component: DpRank,
                        },
                        {
                            path: 'rank/detail',
                            name: '点评榜单详情',
                            component: DpRankDetail,
                        },
                        {
                            path: 'rank/shop',
                            name: '点评榜单门店',
                            component: DpRankShop,
                        },
                        {
                            path: 'cpc/plan/detail',
                            name: '推广详情',
                            component: DpCpcPlanDetail,
                        },
                    ]
                },
                {
                    path: 'wx/work',
                    name: 'WX_WORK',
                    component: Empty,
                    children: [
                        {
                            path: 'corp',
                            name: '企业信息',
                            component: WorkCorp,
                        },
                        {
                            path: 'corp/detail',
                            name: '企业详情',
                            component: WorkCorpDetail,
                        },
                        {
                            path: 'groupChat/detail',
                            name: '群聊详情',
                            component: WorkGroupChatDetail,
                        },
                        {
                            path: 'qrcode/group',
                            name: '组合码',
                            component: WorkQrcodeGroup,
                        },
                        {
                            path: 'qrcode/group/detail',
                            name: '组合码详情',
                            component: WorkQrcodeGroupDetail,
                        },
                    ]
                },
                {
                    path: 'k',
                    name: 'K',
                    component: Empty,
                    children: [
                        {
                            path: 'kol/dp',
                            name: '点评KOL',
                            component: DpKol,
                        },
                        {
                            path: 'kol/dy',
                            name: '抖音KOL',
                            component: DyKol,
                        },
                        {
                            path: 'kol/xhs',
                            name: '小红书KOL',
                            component: XhsKol,
                        },
                        {
                            path: 'kol/detail',
                            name: 'KOL详情',
                            component: KolDetail,
                        },
                        {
                            path: 'task',
                            name: '活动',
                            component: Task,
                        },
                        {
                            path: 'task/detail',
                            name: '活动详情',
                            component: TaskDetail,
                        },
                    ]
                }
            ]
        }
    ],
    // mode: 'history',
})

const whiteList = ['/login', '/gallery', '/dp/shop/analysis', '/dp/shop/summary', '/dp/shop/compareByDate', '/dp/shop/compareByShop', '/k/task/merchant']


// 导航守卫，渲染动态路由，权限控制
router.beforeEach((to, from, next) => {
    NProgress.start();
    if (whiteList.indexOf(to.path) !== -1) {
        next()
    } else {
        let user = db.getUser();
        if (!user.token) {
            next({path: '/login'})
        } else {
            next()
        }
    }
})

export default router
